package com.learn;

import java.util.Arrays;

public class num_66 {
    public static int[] plusOne(int[] digits) {
        if (digits[0] == 0 && digits.length == 1) {
            return new int[]{1};
        }
        int last = digits.length - 1;
        int up = 0;
        digits[last] += 1;

        for (int i = last ; i >= 0; i--) {
            digits[i]+=up;
            if (digits[i] / 10 > 0) {
                up=1;
                digits[i]-=10;
            }else if (digits[i]!=0){
                //digits[i]+=up;
                up=0;
                System.out.println("这里退出了");
                return digits;
            }
        }
        digits=new int[digits.length+1];
        digits[0]=1;
        return digits;
    }

    public static void main(String[] args) {
        int[] nums = {9,9,9};
        //19999+1==20000;
        int[] ints = plusOne(nums);
        System.out.println(Arrays.toString(ints));
    }
}
